<template>
  <!--  发货区域，支持选择快递-->
  <j-modal
    width="1200px"
    :title="title"
    :visible="visible"
    switchFullscreen
    @cancel="handleCancel"
    :confirmLoading="confirmLoading"
  >
    <template slot="footer">
      <a-button @click="handleCancel">取消</a-button>
      <a-button @click="handleOk" type="primary" v-if="!disableSubmit">确认</a-button>
    </template>
    <a-form :form="form">
      <a-row :gutter="24">

        <a-col :md="8" :sm="24">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="是否结算"
          >
            <a-select :disabled='disableSubmit'
                      placeholder="是否结算"
                      v-decorator="['isSettlement',validatorRules.productName]"
                      >
              <a-select-option :value='1'>
                是
              </a-select-option>
              <a-select-option :value='0'>
                否
              </a-select-option>
            </a-select>
<!--            <a-input placeholder="是否结算" v-decorator="['isSettlement',validatorRules.productCode]"-->
<!--                     :disabled="disableSubmits"/>-->
          </a-form-item>
        </a-col>
        <a-col :md="8" :sm="24">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="整车简装"
          >
            <a-select :disabled='disableSubmit'
                      placeholder="整车简装" v-decorator="['isFull',validatorRules.productName]"
            >
              <a-select-option :value='1'>
                是
              </a-select-option>
              <a-select-option :value='0'>
                否
              </a-select-option>
            </a-select>
<!--            <a-input placeholder="整车简装" v-decorator="['isFull',validatorRules.productCode]"-->
<!--                     :disabled="disableSubmits"/>-->
          </a-form-item>
        </a-col>
        <a-col :md="8" :sm="24">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="物流公司"
          >
            <a-input placeholder="物流公司" v-decorator="['logistics',validatorRules.productName]"
                            :disabled="disableSubmit"/>
          </a-form-item>
        </a-col>

        <a-col :md="8" :sm="24">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="车型"
            hasFeedback
          >
            <a-input placeholder="车型" :disabled="disableSubmit"
                     v-decorator="['model',validatorRules.productName]"></a-input>
          </a-form-item>
        </a-col>
        <a-col :md="8" :sm="24">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="车牌号"
            hasFeedback
          >
            <a-input placeholder="车牌号" :disabled="disableSubmit"
                     v-decorator="['carNumber',validatorRules.productName]"></a-input>
          </a-form-item>
        </a-col>
        <a-col :md="8" :sm="24">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="司机姓名"
            hasFeedback
          >
            <a-input placeholder="司机姓名" :disabled="disableSubmit"
                     v-decorator="['driverName',validatorRules.productName]"></a-input>
          </a-form-item>
        </a-col>
        <a-col :md="8" :sm="24">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="司机电话"
            hasFeedback
          >
            <a-input placeholder="司机电话" :disabled="disableSubmit"
                     v-decorator="['driverTel',validatorRules.productName]"></a-input>
          </a-form-item>
        </a-col>
        <a-col :md="8" :sm="24">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="订单数量合计"
            hasFeedback
          >
            <a-input placeholder="订单数量合计" :disabled="disableSubmit"
                     v-decorator="['orderNum',validatorRules.productName]"></a-input>
          </a-form-item>
        </a-col>
        <a-col :md="8" :sm="24">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="标准件合计"
            hasFeedback
          >
            <a-input placeholder="标准件合计" :disabled="disableSubmit"
                     v-decorator="['orderStandNum',validatorRules.productName]"></a-input>
          </a-form-item>
        </a-col>
        <a-col :md="8" :sm="24">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="重量合计"
            hasFeedback
          >
            <a-input placeholder="重量合计" :disabled="disableSubmit"
                     v-decorator="['weightNum',validatorRules.productName]"></a-input>
          </a-form-item>
        </a-col>
        <a-col :md="8" :sm="24">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="推荐车型"
            hasFeedback
          >
            <a-input placeholder="推荐车型" :disabled="disableSubmit"
                     v-decorator="['recommendCar',validatorRules.productName]"></a-input>
          </a-form-item>
        </a-col>
        <a-col :md="8" :sm="24">
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="调度状态"
            hasFeedback
          >
            <a-select placeholder="调度状态" :disabled="disableSubmit"
                      v-decorator="['mergeStatus',validatorRules.productName]"
            >
              <a-select-option :value='0'>
                未调度
              </a-select-option>
              <a-select-option :value='1'>
                已调度
              </a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
      </a-row>
    </a-form>
    <div style='margin-bottom: 10px'>
      <a-button @click="productSearch" :disabled="disableSubmit" type="primary">添加</a-button>
      <a-button @click="handelDelete" :disabled='selectedRowKeys<=0 || disableSubmit' style='margin-left: 12px'>删除</a-button>
    </div>

    <a-table
      ref="table"
      size="middle"
      class='Table'
      bordered
      rowKey="id"
      :scroll="{x:1500,y:pageHeight-seachHeight-220}"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      :customRow="onClickRow"
      :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
      @change="handleTableChange">
    </a-table>
    <proChose ref="prochoose" :name='name' @okbro="okbropro"></proChose>
  </j-modal>
</template>

<script>
import { getAction, postAction } from '@/api/manage'
import proChose from './proChose'
import { pick } from 'lodash'
import { PageListMixin } from '@/mixins/PageListMixin'
import { filterObj,randomString } from '@/utils/util'
export default {
  name: 'manageModal',
  mixins:[PageListMixin],
  description:'货补新增',
  components: {
    proChose
  },
  data() {
    return {
      name:'',
      disableMixinCreated:true,
      disableSubmit: false,
      disableSubmits: false,
      title: '',
      confirmLoading: false,
      form: this.$form.createForm(this),
      model: {},
      visible: false,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 8 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      columns: [
        {
          title: '订单编号',
          align: 'center',
          width: 200,
          ellipsis: true,
          dataIndex: 'orderCode'

        },
        {
          title: '经销商编号',
          align: 'center',
          width: 200,
          ellipsis: true,
          dataIndex: 'custCode'
        },
        {
          title: '经销商名称',
          align: 'center',
          width: 100,
          dataIndex: 'custName'
        },
        {
          title: '商品总数',
          align: 'center',
          width: 100,
          dataIndex: 'totalNum'
        },
        {
          title: '订单金额',
          align: 'center',
          width: 100,
          dataIndex: 'totalAmount'
        },
        {
          title: '优惠金额',
          align: 'center',
          width: 100,
          dataIndex: 'disAmount'
        },
        {
          title: '折扣抵扣',
          align: 'center',
          width: 100,
          dataIndex: 'disFee'
        },
        {
          title: '货补抵扣',
          align: 'center',
          width: 100,
          dataIndex: 'hbFee'
        },
        {
          title: '实际支付',
          align: 'center',
          width: 100,
          dataIndex: 'realAmount'
        },
        {
          title: '送达方',
          align: 'center',
          width: 100,
          dataIndex: 'kunwe'
        },
        {
          title: '送达方名称',
          align: 'center',
          width: 300,
          dataIndex: 'kunweName'
        },
        {
          title: '收货人',
          align: 'center',
          width: 100,
          dataIndex: 'consignee'
        },
        {
          title: '收货人电话',
          align: 'center',
          width: 150,
          dataIndex: 'consigneePhone'
        },
      ],
      url: {
        list: window._CONFIG['domianDmsURL'] + '/merge/findOrderPageList',
        delete:window._CONFIG['domianDmsURL'] + '/merge/deleteItem',
        sendOrder: window._CONFIG['domianDmsURL'] + '/merge/saveOrUpdateEntity'
      },
      validatorRules: {
        productName: {
          rules: [
            { required: true, message: '' }
          ]
        },
      },
      modal: undefined,

    }
  },

  watch:{

  },
  methods: {

    handelDelete(){
      getAction(this.url.delete,{ids:this.selectedRowKeys+''}).then(res=>{
        if(res.success){
          this.loadData()
          this.selectedRowKeys=[]
          this.selectionRows=[]
        }else {
          this.$message.error(res.message)
        }
      })
    },

    productSearch(status) {
      this.$refs.prochoose.rowKey='orderCode'
      let formconfig = [
        {
          key: 'orderCode',
          label: '订单号'
        },
        {
          key: 'custCode',
          label: '经销商编号'
        },
        {
          key: 'custName',
          label: '经销商名称'
        },
      ]
      let tableconfig = {
        columns: [
          {
            title: '订单编号',
            align: 'center',
            width: 200,
            ellipsis: true,
            dataIndex: 'orderCode'

          },
          {
            title: '经销商编号',
            align: 'center',
            width: 200,
            ellipsis: true,
            dataIndex: 'custCode'
          },
          {
            title: '经销商名称',
            align: 'center',
            width: 100,
            dataIndex: 'custName'
          },
          {
            title: '商品总数',
            align: 'center',
            width: 100,
            dataIndex: 'totalNum'
          },
          {
            title: '订单金额',
            align: 'center',
            width: 100,
            dataIndex: 'totalAmount'
          },
          {
            title: '优惠金额',
            align: 'center',
            width: 100,
            dataIndex: 'disAmount'
          },
          {
            title: '折扣抵扣',
            align: 'center',
            width: 100,
            dataIndex: 'disFee'
          },
          {
            title: '货补抵扣',
            align: 'center',
            width: 100,
            dataIndex: 'hbFee'
          },
          {
            title: '实际支付',
            align: 'center',
            width: 100,
            dataIndex: 'realAmount'
          },
          {
            title: '送达方',
            align: 'center',
            width: 100,
            dataIndex: 'kunwe'
          },
          {
            title: '送达方名称',
            align: 'center',
            width: 300,
            dataIndex: 'kunweName'
          },
          {
            title: '收货人',
            align: 'center',
            width: 100,
            dataIndex: 'consignee'
          },
          {
            title: '收货人电话',
            align: 'center',
            width: 150,
            dataIndex: 'consigneePhone'
          },
      ],
        list: window._CONFIG['domianDmsURL'] + '/merge/findOrderPageList',
        multiple: true,
        columW: 60
      }
      this.name = '订单'
      let dataSource = []
      if(this.form.getFieldValue('productCode')){
        dataSource = [{
          productCode:this.form.getFieldValue('productCode'),
          productName:this.form.getFieldValue('productName')
        }]
      }
      this.$refs.prochoose.tempUuid=this.queryParam.tempUuid
      this.$refs.prochoose.edit(formconfig, tableconfig, status,dataSource)
    },

    okbropro(record, status) {
      this.loadData()
    },
    add(record, status) {
      this.edit(record, status)
    },
    edit(iscord) {
      this.queryParam={}
      this.disableSubmits = false
      this.form.resetFields()
      this.modal = undefined
      if(iscord&&iscord.tempUuid){
        this.queryParam.tempUuid=iscord.tempUuid
      }else {
        this.queryParam.tempUuid=randomString(32)
      }
      this.loadData()
      this.visible = true
      if (typeof iscord !== 'undefined') {
        this.disableSubmits = true
        this.modal = Object.assign({}, iscord)
        this.$nextTick(() => {
          this.form.setFieldsValue({ ...this.modal })
        })
      }
    },
    handleOk() {
      let _vm = this
      this.form.validateFields((err, values) => {
        if (!err) {
          this.confirmLoading = true
          let formData = { ...this.modal, ...values,tempUuid:this.queryParam.tempUuid }
          postAction(this.url.sendOrder, formData).then(res => {
            if (!res.success) {
              this.$message.error(res.message)
            } else {
              this.$emit('ok')
            }
            _vm.confirmLoading = false
          })
        }
      })
    },
    handleCancel() {
      this.visible = false
      this.confirmLoading = false
    },
    close() {
      this.handleCancel()
    }
  }

}
</script>

<style scoped>

</style>